package com.toobigtofail.entities
{
	import com.toobigtofail.Game;
	
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.Graphic;
	import net.flashpunk.Mask;
	import net.flashpunk.graphics.Spritemap;
	
	public class Village extends Entity
	{
		[Embed(source="/assets/gfx/basicvillage1.png")] private static const VILLAGE_PNG:Class;
		private var _isEnemy:Boolean;
		private var _image:Spritemap;
		
		private var _spawnTimer:Number = 0;
		private var _spawnTime:Number = 3;
		
		public function Village(isEnemy:Boolean)
		{
			_image = new Spritemap(VILLAGE_PNG, 200, 320);
			_image.centerOO();
			
			_isEnemy = isEnemy;
			
			if(_isEnemy)
			{
				x = (FP.world as Game).ENEMY_BASE.x;
				y = (FP.world as Game).ENEMY_BASE.y;
				_image.flipped = true;
			}
			else
			{
				x = (FP.world as Game).PLAYER_BASE.x;
				y = (FP.world as Game).PLAYER_BASE.y;
			}
				graphic = _image;
			
			super(x, y, graphic, mask);
		}
		
		
		override public function update():void
		{
			super.update();
			spawnVillager();
		}
		
		public function spawnVillager():void
		{
			_spawnTimer += FP.elapsed;
			if(_spawnTimer > _spawnTime)
			{
				_spawnTimer = 0;
				FP.world.add(new Villager(x, _isEnemy));
			}
		}
	}
}